# -*- coding: utf-8 -*-
from http.client import HTTPException


class Success(HTTPException):
    code = 0
    message = 'success'

    def __init__(self, code=None, data=None):
        # if message:
        #     self.message = message
        super(Success, self).__init__()
        self.data = data
        self.code = code


class ServiceFailure(HTTPException):
    """
        exception sed when an service_level error happen.
    """
    code = 200

    def __init__(self, error_code, message, data):
        super(ServiceFailure, self).__init__()
        self.description = message
        self.data = {"code": error_code, "message": message, "data": data}


class ServiceERROR(HTTPException):
    """
        exception sed when an service_level error happen.
    """
    code = 400

    def __init__(self, error_code, message, data):
        super(ServiceERROR, self).__init__()
        self.description = message
        self.data = {"code": error_code, "message": message, "data": data}


class AuthFailure(HTTPException):
    """
        exception sed when fail to authorize.
    """
    code = 200

    def __init__(self, message):
        super(AuthFailure, self).__init__()
        self.description = message
        self.data = {"code": 401, "message": message}


class NotFound(HTTPException):
    code = 200

    def __init__(self, message=None):
        super(NotFound, self).__init__()
        self.description = message if message else "资源不存在"
        self.data = {"code": 404, "message": message}


class IllegalParams(HTTPException):
    """
        exception raised when illegal args received.
    """
    code = 422

    def __init__(self, message, data):
        super(IllegalParams, self).__init__()
        self.description = message
        self.data = {"code": 422, "message": message, "data": data}


class InternalError(HTTPException):
    """
        exception raised when an internal error happen.
    """
    code = 500

    def __init__(self, message):
        super(InternalError, self).__init__()
        self.description = message
        self.data = {"code": 500, "message": message}
